package com.hmis.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hmis.domain.CheckItem;
import com.hmis.domain.Patient;
import com.hmis.domain.Prescription;
import com.hmis.mapper.PatientMapper;
import com.hmis.service.CheckItemService;
import com.hmis.service.PatientService;
import com.hmis.service.PrescriptionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Edward
 * @description 针对表【patient(病人信息表)】的数据库操作Service实现
 * @createDate 2023-04-10 20:53:32
 */
@Service
public class PatientServiceImpl extends ServiceImpl<PatientMapper, Patient>
        implements PatientService {

    @Autowired
    PrescriptionService prescriptionService;
    @Autowired
    CheckItemService checkItemService;

    @Override
    public Patient updatePatientNameById(Patient patient) {
        this.updateById(patient);
        QueryWrapper<Prescription> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("patient_id", patient.getPatientId()).eq("is_delete", 0);
        Prescription prescription = prescriptionService.getOne(queryWrapper);
        prescription.setPatientName(patient.getPatientName());
        prescriptionService.updatePrescriptionByPatientId(prescription);
        QueryWrapper<CheckItem> queryWrapper1 = new QueryWrapper<>();
        queryWrapper1.eq("patient_id", patient.getPatientId()).eq("is_delete", 0);
        List<CheckItem> checkItems = checkItemService.list(queryWrapper1);
        for (CheckItem checkItem : checkItems) {
            checkItem.setPatientName(patient.getPatientName());
            checkItemService.updateById(checkItem);
        }
        return patient;
    }
}




